package com.cow.net.udp


import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioDatagramChannel
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component;

/**
 * Created by maqi on 2018/1/12.
 */

class UdpReceiver {


    int port = 800
    public void run( ) {
        EventLoopGroup group = new NioEventLoopGroup();
    try {
        //先建立tcp连接



        try {

        }catch (Exception e)
        {
            e.printStackTrace();
        }

        Bootstrap b = new Bootstrap();
        //由于我们用的是UDP协议，所以要用NioDatagramChannel来创建
        b.group(group).channel(NioDatagramChannel.class)
                .option(ChannelOption.SO_BROADCAST, true)//支持广播
                .handler(new UdpProverbServerHandler(client));//ChineseProverbServerHandler是业务处理类
        b.bind(port).sync().channel().closeFuture().await();
    }
    catch (Exception e) {
    throw new RuntimeException(e);
     }
    finally {
       group.shutdownGracefully();

}
    }

}
